package com.hakim.wfb.sms.service.impl;

import constant.Constants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import utils.SmsClientSend;

/**
 * Created by lenovo on 2017/7/22.
 */
public class SmsMsgSendServiceImpl {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    public static String url = Constants.Msg_Url;// "http://120.55.197.228/sms.aspx";
    public static String userid = Constants.Msg_User_Id;// "727";
    public static String account = Constants.Msg_Account;// "SDK-A638-727";
    public static String password = Constants.Msg_Password;// "ccb1c065b3120d5a2d083d6368b764db";

    public static String mobile = "18600992571";
    public static String content = "【久福积分】您本次请求注册的验证码是:{%s},5分钟内有效。";

    public static void main(String[] args) {
        // 剩余短信数量查询；
       /* String overage = SmsClientOverage.queryOverage(url, userid, account,
                password);
        System.out.println(overage);*/
//        if (overage.overage<=1000)

        // 发送短信接口方法；
        SmsClientSend smsClientSend = new SmsClientSend();
        String sendRet = smsClientSend.sendSms(url, userid, account,
                password, mobile, String.format(content, (int) (Math.random() * Math.pow(10, 5))));
        System.out.println(sendRet);

        boolean res = new SmsMsgSendServiceImpl().sendMsg("18600992571",
                String.format(content, (int) (Math.random() * Math.pow(10, 5))));
        System.out.println(res);
    }

    public boolean sendMsg(String tels, String msg) {
        String smsUrl = Constants.Msg_Url;
        String status = Constants.SuDun_SMS_STATUS;
        String result;
        try {
            SmsClientSend smsClientSend = new SmsClientSend();
            String retMsg = smsClientSend.sendSms(url, userid, account,
                    password, tels, String.format(content, msg));
            if (retMsg.contains("Success")) {
                return true;
            }
        } catch (Exception e) {
            return false;
        }
        return true;
    }


}
